<template>
    <a-row>
        <a-input-search v-model:value="searchKey" placeholder="请输入电缆信息" style="width: 200px; margin-bottom: 10px;"
            @search="onSearch()" />
    </a-row>

    <a-table :rowKey="(record) => record.id" :row-selection="rowSelection" :dataSource="dataSource" :columns="columns"
        bordered :scroll="{ x: 1000 }" :pagination="false">
        <template #bodyCell="{ column, text, record }">
            {{ text }}
        </template>
    </a-table>
    <AntdZh>
        <a-pagination v-model:current="query.pageNum" v-model:pageSize="query.pageSize" :total="total" @change="getList" />
    </AntdZh>
</template>
<script setup>
import { ref } from 'vue';
import { cloneDeep } from 'lodash-es';
import { queryList } from "@/api/tool/cable.js";
import useApp from "@/hooks";
const { $, proxy } = useApp();
const total = ref(1)
const modalRef = ref(null);
const data = reactive({
    form: {}
});
const { form } = toRefs(data);
const dataSource = ref([]);
// 定义表格列配置
const columns = [
    {
        title: '电缆型号',
        dataIndex: 'cableId',
        key: 'cableId',
        fixed: 'left',
        width: 200
    },
    {
        title: '直径(mm)',
        dataIndex: 'diameter',
        key: 'diameter',
        width: 110
    },
    {
        title: '空气中重量(kg/km)',
        dataIndex: 'weight',
        key: 'weight',
        width: 110
    },
    {
        title: '耐温(℃)',
        dataIndex: 'temperatureResistance',
        key: 'temperatureResistance',
        width: 110
    },
    {
        title: '耐压(MPa)',
        dataIndex: 'voltageResistance',
        key: 'voltageResistance',
        width: 110
    },
    {
        title: '拉断力(KN)',
        dataIndex: 'breakingForce',
        key: 'breakingForce',
        width: 110
    },
    {
        title: '弯曲直径(mm)',
        dataIndex: 'bendingDiameter',
        key: 'bendingDiameter',
        width: 110
    },
    {
        title: '残余伸长量(m/km/5kN)',
        dataIndex: 'residualElongation',
        key: 'residualElongation',
        width: 110
    },
    {
        title: '绝缘电阻(MΩ·km)',
        dataIndex: 'insulationResistance',
        key: 'insulationResistance',
        width: 110
    },
    {
        title: '直流电阻(Ω/km)',
        dataIndex: 'dcResistance',
        key: 'dcResistance',
        width: 110
    },
    {
        title: '电容(pf/m)',
        dataIndex: 'capacitance',
        key: 'capacitance',
        width: 110
    },
    {
        title: '制造商',
        dataIndex: 'manufacturer',
        key: 'manufacturer',
        width: 150
    }
];
const searchKey = ref();
const query = ref({ pageNum: 1, pageSize: 10, sortBy: 'id', searchKey: '' });

const rowSelection = {
    type: 'radio',
    onChange: (selectedRowKeys, selectedRows) => {
        console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
        localStorage.setItem("selectCables", JSON.stringify(selectedRows));
    },
    getCheckboxProps: record => ({
        cableId: record.cableId,
    }),
};

/** 查询井列表 */
function getList() {
    queryList(query.value).then((response) => {
        dataSource.value = response.content;
        total.value = response.totalElements;
    });
}
getList();

/** 搜索按钮操作 */
function onSearch() {
    query.value.searchKey = searchKey;
    getList();
}

/** 表单重置 */
function reset() {
    searchKey.value = '';
    query.value = {
        pageNum: 1, pageSize: 10, sortBy: 'id',
        searchKey: '',
    }
    getList();
}
</script>
  